//
//  RootViewController.swift
//  AudioToolProject
//
//  Created by 邹琳 on 2019/5/6.
//  Copyright © 2019 邹琳. All rights reserved.
//

import UIKit

class RootViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        self.setupChildVC()
        self.tabBar.isTranslucent = false
    }
    
    func setupChildVC(){
        let home = HomeViewController()
        let found = FoundViewController()
        let msg = MessageViewController()
        let rank = RankViewController()
        let mine = MineViewController()
        
        self.addNavi(home, title: "首页".zlLocalizedString, img: "tab_icon_home_")
        self.addNavi(found, title: "发现".zlLocalizedString, img: "tab_icon_society_")
        self.addNavi(msg, title: "消息".zlLocalizedString, img: "tab_icon_home_")
        self.addNavi(rank, title: "排行榜".zlLocalizedString, img: "tab_icon_society_")
        self.addNavi(mine, title: "我的".zlLocalizedString, img: "tab_icon_home_")
    }
    
    func addNavi(_ viewcontroller:UIViewController,title:String,img:String){
        let navi = BaseNavigationViewController(rootViewController: viewcontroller)
        viewcontroller.tabBarItem.setTitleTextAttributes([NSAttributedString.Key.foregroundColor:UIColor(0x909090)], for: .normal)
        viewcontroller.tabBarItem.setTitleTextAttributes([NSAttributedString.Key.foregroundColor:UIColor.black], for: .selected)
        viewcontroller.title = title
        self.setTabImage(viewcontroller, imageName: img)
        self.addChild(navi)
    }
    
    func setTabImage(_ viewcontroller:UIViewController,imageName:String){
        viewcontroller.tabBarItem.image = UIImage(named: imageName+"inactive")?.withRenderingMode(.alwaysOriginal)
        viewcontroller.tabBarItem.selectedImage = UIImage(named: imageName+"active")?.withRenderingMode(.alwaysOriginal)
    }
}
